package com.road.yishi.lottery;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.road.entity.drop.DropItemInfoEx;
import com.road.entity.lottery.LotteryInfo;
import com.road.entity.lottery.LotteryTempInfo;
import com.road.yishi.dao.DaoFactory;
import com.road.yishi.dao.impl.LotteryTempDaoImpl;
import com.road.yishi.pb.vip.VipRouletteMsgProto;

/**
 * @Description :幸运轮盘
 * @FileName: LotteryMgr.java
 * @Author :WeiHui.Zhang
 * @Data : 2016年3月15日 下午3:32:20
 * @Version:V1.00
 */
public class LotteryMgr {

	/**
	 * 格式，全局变量--》功能是否开启配置==》服务端变量==》客户端变量-----分清楚
	 */
	private static final int LOTTERY_TYPES = 1;// 抽奖开关类型
	private static final int MAX_NOTICE_SIZE = 6;// 最多广播消息数量
	private static final int REWARD_ITEM_SIZE = 16;// 抽奖物品数量

	private static boolean isOpen = false;// 是否启用本功能
	private static boolean isInit = true;// 是否开放本功能
	private static boolean isRewardInit = true;// 奖励物品配置是否正确

	private static LotteryTempInfo tempInfo;// 活动模板
	private static Map<Integer, LotteryInfo> userLotteryInfos; // 玩家轮盘信息(k:userId,v:LotteryInfo)
	private static List<DropItemInfoEx> dropItemInfoExs;// 配置的掉落奖励

	private static VipRouletteMsgProto.VipItemInfoMsg.Builder dropItemsPb;// 所有掉落物品PB
	private static List<String> dropNoticeMsgs; // 显示在侧边栏的消息

	public static boolean init() {
		if (!isInit) {
			return true;
		}
		dropNoticeMsgs = new ArrayList<>();
		LotteryTempDaoImpl lotteryTempDaoImpl = DaoFactory.getDaoImpl(LotteryTempDaoImpl.class);
		tempInfo = lotteryTempDaoImpl.getLotteryTempInfo(LOTTERY_TYPES);
		isOpen = readOpenState(tempInfo);
		return true;
	}

	private static boolean readOpenState(LotteryTempInfo tempInfo) {
		long current = System.currentTimeMillis();
		if (tempInfo.getOpenDate() != null && tempInfo.getStopDate() != null) {
			return current >= tempInfo.getOpenDate().getTime() && current < tempInfo.getStopDate().getTime();
		}
		return false;
	}
	
	public static void sendOpenState(){
		if(!isInit){
			return;
		}
	}
}
